package contextjin

import (
	"context"
	"fmt"
	"io"
	"net/http"
)

func Curl(ctx context.Context, url string) error {
	client := http.DefaultClient
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return err
	}

	req = req.WithContext(ctx)

	resp, err := client.Do(req)
	if err != nil {
		return err
	}
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	fmt.Println(string(body))
	return nil
}

type UserName struct{}
type UserRole struct{}

func Payment(
	ctx context.Context,
	tk string,
) error {
	ctx1 := context.WithValue(ctx, UserName{}, "bob")
	ctx2 := context.WithValue(ctx1, UserRole{}, tk)

	DoPayment(ctx2)

	return nil
}

func DoPayment(ctx context.Context) {
	fmt.Println(ctx)
	fmt.Printf("%#v\n", ctx)

	fmt.Println(ctx.Value(UserName{}))
	fmt.Println(ctx.Value(UserRole{}))
}
